﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demos.DesignPatterns._15_模板方法
{
    /// <summary>
    /// 订单处理器
    /// </summary>
    public abstract class TOrderProcessor
    {


        public void ProcessOrder()
        {
            //验证订单
            ValidateOrder();
            //处理支付
            ProcessPayment();

        }

        /// <summary>
        /// 验证订单(通用方法)
        /// </summary>
        /// <returns></returns>
        private bool ValidateOrder()
        {
            Console.WriteLine("验证订单信息");
            return true;
        }
        //必须子类实现的方法
        protected abstract void ProcessPayment();
        protected abstract void ShipOrder();

        /// <summary>
        /// 钩子方法，子类可选择性实现
        /// </summary>
        /// <returns></returns>
        protected virtual bool NeedsGiftWrapping()
        {
            Console.WriteLine("执行NeedsGiftWrapping钩子。。。");
            return false;
        }
        /// <summary>
        /// 钩子方法，子类可选择性实现
        /// </summary>
        protected virtual void GiftWrap()
        {
            Console.WriteLine("默认礼品包装...");
        }
        /// <summary>
        /// 私有方法
        /// </summary>
        private void SendNotification()
        {
            Console.WriteLine("发送订单确认邮件...\n");
        }

    }
}
